<template>
	<div>
		<view class='group-list'>
			<view class='iconfont icon-xiangzuo' @tap='goBack' :style="'top:'+ (navH/2) +'rpx'" v-if="returnShow"></view>
			<view class='header'></view>
			<view class='list'>
				<block v-for="(item,index) in combinationList" :key='index'>
					<view class='item acea-row row-between-wrapper' @tap="openSubcribe(item)"
					 data-url=''>
						<view class='pictrue'>
							<image :src='item.image'></image>
						</view>
						<view class='text'>
							<view class='line1'>{{item.title}}</view>
							<view class='acea-row'>
								<view class='team acea-row row-middle cart-color'>
									<view class='iconfont icon-pintuan'></view>
									<view class='num'>{{item.people}}人团</view>
								</view>
							</view>
							<view class='bottom acea-row row-between-wrapper'>
								<view class='money'>￥<text class='num'>{{item.price}}</text><text class='y-money'>￥{{item.otPrice}}</text></view>
								<view class='groupBnt bg-color'>去拼团<text class="iconfont icon-jiantou"></text></view>
							</view>
						</view>
					</view>
				</block>
				<view class='loadingicon acea-row row-center-wrapper' v-if='combinationList.length > 0'>
					<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
				</view>
			</view>
		</view>
		<home></home>
	</div>
</template>

<script>
	import {
		getCombinationList
	} from '@/api/activity.js';
	import {
		openPinkSubscribe
	} from '../../../utils/SubscribeMessage.js';
	import home from '@/components/home/index.vue'
	let app = getApp();
	export default {
		components: {
			home
		},
		data() {
			return {
				navH: '',
				combinationList: [],
				limit: 10,
				page: 1,
				loading: false,
				loadend: false,
				returnShow: true,
				loadTitle: ''
			}
		},
		onLoad() {
			var pages = getCurrentPages();
			this.returnShow = pages.length===1?false:true;
			uni.setNavigationBarTitle({
				title:"拼团列表"
			})
			this.navH = app.globalData.navHeight;
			this.getCombinationList();
		},
		methods: {
			goBack: function() {
				uni.navigateBack();
			},
			openSubcribe: function(item) {
				let page = item;
				// #ifndef MP
				uni.navigateTo({
					url: `/pages/activity/goods_combination_details/index?id=${item.id}`
				});
				// #endif
				// #ifdef MP
				uni.showLoading({
					title: '正在加载',
				})
				openPinkSubscribe().then(res => {
					uni.hideLoading();
					uni.navigateTo({
						url: `/pages/activity/goods_combination_details/index?id=${item.id}`
					});
				}).catch(() => {
					uni.hideLoading();
				});
				// #endif
			},
			getCombinationList: function() {
				var that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loadTitle = '';
				var data = {
					page: that.page,
					limit: that.limit
				};
				this.loading = true
				getCombinationList(data).then(function(res) {
					let list = res.data.list;
					let combinationList = that.$util.SplitArray(list, that.combinationList);
					let loadend = list.length < that.limit;
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? '已全部加载' : '加载更多';
					that.$set(that, 'combinationList', combinationList);
					that.$set(that, 'page', that.page + 1);
				}).catch(() => {
					that.loading = false;
					that.loadTitle = '加载更多';
				})
			},
		},
		onReachBottom: function() {
			this.getCombinationList();
		},
	}
</script>

<style>
	page {
		background-color: #fa533d !important;
	}

	.icon-xiangzuo {
		font-size: 40rpx;
		color: #fff;
		position: fixed;
		left: 30rpx;
		z-index: 99;
		transform: translateY(-20%);
	}

	.group-list .header {
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 450rpx;
	}

	.group-list .list {
		margin-top: -108rpx;
	}

	.group-list .list .item {
		width: 690rpx;
		height: 208rpx;
		background-color: #fff;
		border-radius: 6rpx;
		padding: 0 24rpx;
		box-sizing: border-box;
		margin: 0 auto 20rpx auto;
	}

	.group-list .list .item .pictrue {
		width: 160rpx;
		height: 160rpx;
	}

	.group-list .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 6rpx;
	}

	.group-list .list .item .text {
		width: 458rpx;
		font-size: 30rpx;
		color: #282828;
	}

	.group-list .list .item .text .team {
		height: 38rpx;
		border-radius: 4rpx;
		font-size: 22rpx;
		margin-top: 20rpx;
	}

	.group-list .list .item .text .team .iconfont {
		width: 54rpx;
		background-color: #ffdcd9;
		text-align: center;
		color: #dd3823;
		height: 100%;
	}

	.group-list .list .item .text .team .num {
		text-align: center;
		padding: 0 6rpx;
		height: 100%;
	}

	.group-list .list .item .text .bottom {
		margin-top: 7rpx;
	}

	.group-list .list .item .text .bottom .money {
		font-size: 24rpx;
		font-weight: bold;
		color: #282828;
	}

	.group-list .list .item .text .bottom .money .num {
		font-size: 32rpx;
	}

	.group-list .list .item .text .bottom .money .y-money {
		font-size: 24rpx;
		color: #999;
		font-weight: normal;
		text-decoration: line-through;
		margin-left: 10rpx;
	}

	.group-list .list .item .text .bottom .groupBnt {
		font-size: 26rpx;
		color: #fff;
		width: 146rpx;
		height: 54rpx;
		text-align: center;
		line-height: 54rpx;
		border-radius: 4rpx;
	}

	.group-list .list .item .text .bottom .groupBnt .iconfont {
		font-size: 25rpx;
		vertical-align: 2rpx;
		margin-left: 10rpx;
	}
</style>
